<template>
  <el-link v-bind="$attrs" :disabled="disabled" v-on="$listeners" v-if="hasAuth"
    ><slot></slot
  ></el-link>
</template>

<script>
import store from '@/store';
/**
 * 按钮权限控制，需要权限控制的独立按钮可以使用此控件
 * 校验规则
 * 当前页面路由path+{按钮btnId}组成按钮权限标识，与权限接口中url参数进行比对，完全一致则认定有权限
 * url示例：/sys-manage/sys-user{btn_add} 会匹配/sys-manage/sys-user页面下btnId为btn_add的按钮
 */
export default {
  name: 'AuthLink',
  props: {
    linkId: {
      type: String,
      required: true,
    },
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  computed: {
    hasAuth() {
      return (
        this.$store.state.permission.btnAuth.indexOf(
          this.$route.path + '{' + this.linkId + '}'
        ) > -1
      );
    },
  },
  created() {},
};
</script>

<style lang="scss" scoped>
</style>
